#ifndef VELOCITY_H
#define VELOCITY_H

#include <math.h>

//#define PI 3.14159265359

void VelocityInit(void);
int GetTimeToWaitBeforeMoveX(int, int);
int GetTimeToWaitBeforeMoveY(int, int);

int thirty_degree_waits[101];
int sixty_degree_waits[101];


void VelocityInit()
{
    int i;

    thirty_degree_waits[0] = 2;
    sixty_degree_waits[0] = 2;

    for (i = 1; i <= 100; i++) {
        thirty_degree_waits[i] = (int)ceil((((float)i / ((float)i * (float)sin((float)30 / (float)180 * PI))) * (float)i));
        sixty_degree_waits[i] = (int)ceil((((float)i / ((float)i * (float)sin((float)60 / (float)180 * PI))) * (float)i));
    }
}


int GetTimeToWaitBeforeMoveX(int ortho_velocity, int angle)
{
    int wait_time_x = 999;

    if (ortho_velocity < 1) {
        ortho_velocity = 1;
    }
    else if (ortho_velocity > 100) {
        ortho_velocity = 100;
    }

    switch (angle) {
        case 90:
        case 270:
            wait_time_x = ortho_velocity;
            break;

        case 30:
        case 150:
        case 210:
        case 330:
            wait_time_x = thirty_degree_waits[ortho_velocity];
            break;

        case 60:
        case 120:
        case 240:
        case 300:
            wait_time_x = sixty_degree_waits[ortho_velocity];
            break;
    }

    return wait_time_x;
}


int GetTimeToWaitBeforeMoveY(int ortho_velocity, int angle)
{
    int wait_time_y = 999;

    if (ortho_velocity < 1) {
        ortho_velocity = 1;
    }
    else if (ortho_velocity > 100) {
        ortho_velocity = 100;
    }

    switch (angle) {
        case 0:
        case 180:
            wait_time_y = ortho_velocity;
            break;

        case 30:
        case 150:
        case 210:
        case 330:
            wait_time_y = sixty_degree_waits[ortho_velocity];
            break;

        case 60:
        case 120:
        case 240:
        case 300:
            wait_time_y = thirty_degree_waits[ortho_velocity];
            break;
    }

    return wait_time_y;
}

#endif
